<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let num1 = +prompt('请输入一个数')
    function isnum(num){
      let str = 1
      let length = String(num).length
      for(let i = 1; i < length; i++){
        str += '0'
      }
      // 比较的次数
      for(let i = 1; i<=(length / 2); i++){
        let a = parseInt(num / str)
        let b = parseInt(num % 10)
        // 获取首位和末尾
        // 只要有一次比较不相等，就退出函数
        if(a != b){
          return `${num1}不是一个回文数`
        }
        // 把已经比较过的首位和末位去除
        num = num % str
        num = parseInt(num / 10)
        // 少了两位数，str也相应少两位
        str = str / 100
      }

      return `${num1}是一个回文数`
    }
    console.log(isnum(num1));
  </script>
</body>
</html>